﻿using BarcodeDelay.bean;
using BarcodeDelay.FrameDecoder;
using BarcodeDelay.logHelp;
using BarcodeDelay.utility;
using JTParcrelHelper.bean;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace BarcodeDelay.business
{
    public class InterceptMessageHelper
    {
        private StreamWriter swb = null;
        FileStream bFile = null;
        ArrayList m_arListDepBarcodes = new ArrayList();
        public event Action DoneHttpResponse;
        public event Action GotInterceptBarcode;
        private string m_strCurBarcode = "";
        ArrayList m_arListBarcodes = new ArrayList();
        ArrayList arListArbitrationBarcodes = new ArrayList();
        private bool isInProcess = false;

        private bool isCuiTypeWhenAssign = true;
        private DateTime dtLastInter = System.DateTime.Now;
        Hashtable htInterNoRoadMap = new Hashtable();


        public Hashtable htInterCeptFaile = new Hashtable();

        Hashtable htAutoTaskAssigned = new Hashtable();
        private static InterceptMessageHelper instance;
        public static InterceptMessageHelper Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new InterceptMessageHelper();
                }
                return instance;
            }
        }
        private Thread fThreadDep = null;
        public void BeginAnalyThread(ArrayList  arListBarcodes, string anayType)
        {
            try
            {
                m_arListBarcodes.Clear();
                if (fThreadDep != null && (fThreadDep.ThreadState == ThreadState.Running || fThreadDep.ThreadState == ThreadState.Background))
                {
                    fThreadDep.Abort();
                    System.Threading.Thread.Sleep(50);
                }
                if (fThreadDep != null && (fThreadDep.ThreadState == ThreadState.Running || fThreadDep.ThreadState == ThreadState.Background))
                {
                    while (fThreadDep.ThreadState != ThreadState.Aborted)
                    {
                        //当调用Abort方法后，如果thread线程的状态不为Aborted，主线程就一直在这里做循环，直到thread线程的状态变为Aborted为止
                        Thread.Sleep(100);
                    }
                }

                m_arListBarcodes = arListBarcodes;
                //m_arListDepBarcodes = arListBarCodes;
                //fThreadDep = new Thread(new ThreadStart(handleAllBarcodes));//出港分析 开辟一个新的线程
                //fThreadDep.IsBackground = true;
                //fThreadDep.Start();

                fThreadDep = new Thread(new ParameterizedThreadStart(handleAllBarcodes));
                fThreadDep.Start((object)arListBarcodes);


            }
            catch (Exception ex)
            {

            }
        }

        public void handleInprocessTransfer(string billcode,out string outMsg)
        {
            outMsg = "";
            try
            {
                JObject jObj = new JObject();
                //查询是否有待审核
                string queryUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/rebackTransferExpress/problemExpressPage";
                

                if (StoParams.Instance.isRabbitWin)
                {
                    queryUrl = "https://wdgw.jtexpress.com.cn/ops/wdbutler/rebackTransferExpress/applyForPage";

                    jObj["applyNetworkId"] = Convert.ToInt32(StoParams.Instance.register_networkId);
                    jObj["applyTypeCode"] = 5;
                }
                
                jObj["current"] = 1;
                jObj["size"] = 20;
                jObj["auditNetworkId"] = Convert.ToInt32(StoParams.Instance.register_networkId);
                jObj["applyTimeFrom"] = System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + " " + "00:00:00"; 
                jObj["applyTimeTo"] = System.DateTime.Now.ToString("yyyy-MM-dd") + " " + "23:59:59"; 
                jObj["status"] = 1;
                jObj["countryId"] = "1";
                JArray jarr = new JArray();
                jarr.Add(billcode);
                jObj["waybillIds"] = jarr;
                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string res = HttpClient.HttpUtil.Instance.PostCommon(queryUrl, postData, "returnAndForwardMaintain");

                JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(res);
                JObject dataObj = (JObject)jsonObjRes["data"];

                JArray records = (JArray)dataObj["records"];
                if (records.Count == 0)
                {
                    return;
                }
                string codeStr = "";
                bool isFind = false;
                for (int i = 0; i < records.Count; i++)
                {
                    JObject jsonObjFirst = (JObject)records[0];
                    JToken waybillToken = jsonObjFirst["waybillNo"];
                    if(waybillToken.ToString()== billcode)
                    {
                        JToken statusName = jsonObjFirst["statusName"];
                        JToken applyTypeName = jsonObjFirst["applyTypeName"];
                        if(statusName.ToString()== "待审核"&& applyTypeName.ToString()== "修改收件地址")
                        {
                            isFind = true;
                            break;
                        }
                    }
                }
                if(isFind)
                {
                    //撤销改地址
                    queryUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/rebackTransferExpress/revocation";

                    if (StoParams.Instance.isRabbitWin)
                    {
                        queryUrl = "https://wdgw.jtexpress.com.cn/ops/wdbutler/rebackTransferExpress/revocation";
                    }

                    jObj = new JObject();
                    
                    jObj["reason"] = "";
                    jObj["countryId"] = "1";
                    jarr = new JArray();
                    jarr.Add(billcode);
                    jObj["waybillIds"] = jarr;
                    postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                    res = HttpClient.HttpUtil.Instance.PostCommon(queryUrl, postData, "interceptQueryBackNew");

                    jsonObjRes = (JObject)JsonConvert.DeserializeObject(res);
                    JToken sucToken = (JToken)jsonObjRes["succ"];
                    if(sucToken.ToString().ToLower()=="true")
                    {
                        outMsg = "撤销改地址成功";
                    }

                }
            }
            catch(Exception ex)
            {

            }
        }

        public void handleAllBarcodes(object arListDepBarcodes)
        {
            try
            {
                string outmsg = "";
                /*if(arListArbitrationBarcodes.Count==0)
                {
                    arListArbitrationBarcodes = JTDelayHelper.Instance.getArbitrationBarcodes(out outmsg);
                }*/
                

                isInProcess = true;

                ArrayList countArr = (ArrayList)arListDepBarcodes;
                int totalCount = countArr.Count;
                //if (totalCount>10)
                {
                    LogHelper.Instance.writeLog("收到拦截任务个数："+ totalCount.ToString());
                }

                ArrayList arListNoRoadMap = new ArrayList();

                foreach (ParcelBean parcelBean in (ArrayList)arListDepBarcodes)
                {
                   
                    string strBarcode = parcelBean.wayBill;       
                    if(strBarcode.Length<10)
                    {
                        continue;
                    }

                    if(parcelBean.taskType.Contains("自动"))
                    {
                        LogHelper.Instance.writeLog(parcelBean.taskType  +" "+ strBarcode);
                        FrameDecoderManager.Instance.htTaskCheck[parcelBean] = System.DateTime.Now;
                    }
                    string pickName = "";
                    string curBarcodeToken = "";
                    string orderSource = "";
                    string curSiteToken = "";
                    string customerName = "";

                    ArrayList arListAllGXTask3 = new ArrayList();
    
                    string httpRes = "";
                    ArrayList arListRoadMap = JTDelayHelper.Instance.getRoadMap(strBarcode, out httpRes, arListAllGXTask3);
                    string lanshouSite = JTDelayHelper.Instance.getLanShouSite(arListRoadMap);
                    bool isQianshou = JTDelayHelper.Instance.isQianshou(arListRoadMap);
                    if (!UtilityHelp.Instance.resetToken(strBarcode,out pickName,out orderSource,out curSiteToken,out customerName))
                    {
               
                        if (curSiteToken=="")
                        {
                            StoParams.Instance.htResWechat[strBarcode] = " 发件网点 " + pickName + " 登录失效";
                            FrameDecoderManager.Instance.htFailedParcel[strBarcode] = System.DateTime.Now;

                            if (pickName != "" && StoParams.Instance.isStrictMode)
                            {
                                if (StoParams.Instance.register_site != pickName&& pickName.Length>3)
                                {
                                    StoParams.Instance.htResWechat[strBarcode] = "发件网点"+ pickName+ "  非我司单号  无法处理";
                                }
                            }
                            continue;                          
                                     
                        }

                       

                        if (lanshouSite!= pickName&& lanshouSite.Length>2)
                        {
                            pickName = lanshouSite;
                        }
                        bool findSite = false;
                        foreach (DictionaryEntry de in StoParams.Instance.htDifferentSiteBarcodeInfo)
                        {
                            if(de.Key.ToString()== pickName)
                            {
                                findSite = true;
                                break;
                            }
                        }
                        if(!findSite)
                        {
                            StoParams.Instance.htResWechat[strBarcode] = " 发件网点 " + pickName + " 非我司单号  无法处理";
                            if (pickName != "" && StoParams.Instance.isStrictMode)
                            {
                                if (StoParams.Instance.register_site != pickName)
                                {
                                    StoParams.Instance.htResWechat[strBarcode] = "发件网点" + pickName + "  非我司单号  无法处理";
                                }
                            }
                            continue;
                        }
                            
                     }
                    parcelBean.lanshouSite = pickName;
                    parcelBean.customerName = customerName;
                    UtilityHelp.Instance.resetWechat(parcelBean, pickName);

                    if (totalCount > 10)
                    {
                        if(!StoParams.Instance.register_site.Contains("永平") && !StoParams.Instance.register_site.Contains("凤岗"))
                        {
                            System.Threading.Thread.Sleep(1600);
                        }
                        
                    }
                    else
                    {
                        TimeSpan ts = System.DateTime.Now - dtLastInter;
                        if(ts.TotalSeconds<1.5)
                        {
                            if (!StoParams.Instance.register_site.Contains("永平")&& !StoParams.Instance.register_site.Contains("凤岗"))
                            {
                                System.Threading.Thread.Sleep(200);
                            }
                               
                        }
                        
                    }
                    /*if (arListArbitrationBarcodes.Contains(strBarcode))
                    {
                        StoParams.Instance.interResMsg = strBarcode+ " 已申请过仲裁";
                        DoneHttpResponse();
                        continue;
                    }*/

                    
                    string outTransferMsg = "";
                    if(!isQianshou)
                    {
                        handleInprocessTransfer(strBarcode, out outTransferMsg);
                    }
                    

                    string outMsg = "";
                    string lastUpdateTime = "";
                    //JTDelayHelper.Instance.getCommentsContent(strBarcode, out outMsg, out lastUpdateTime);


                    if (lastUpdateTime != "")
                    {
                        TimeSpan tsCur = System.DateTime.Now - Convert.ToDateTime(lastUpdateTime);
                        /*if (tsCur.TotalHours < 24)
                        {
                            StoParams.Instance.curParces++;
                            continue;
                        }*/
                    }
                    m_strCurBarcode = strBarcode;
                    StoParams.Instance.interResMsg = "";
                    ArrayList arListAllGXTask = new ArrayList();
                  
                    


                    string returnMySite2 = "";
                    if (JTDelayHelper.Instance.isLastSiteIsMyself(arListRoadMap, out returnMySite2))
                    {
                        StoParams.Instance.htResWechat[strBarcode] = returnMySite2;
                        System.Threading.Thread.Sleep(100);
                        continue;
                    }

                    string lanshouTime = JTDelayHelper.Instance.getLanShouTime(arListRoadMap);
                    parcelBean.lanshouTime = lanshouTime;

                    if (arListRoadMap.Count == 0)
                    {
                        if (!parcelBean.taskType.Contains("自动"))
                        {
                            parcelBean.isAutoCancel = true;
                            arListNoRoadMap.Add(parcelBean);
                        }
                            
                        StoParams.Instance.interResMsg = httpRes;
                        if(httpRes.Contains("成功"))
                        {
                            string resMsg = "快件未发出无法拦截，后续跟踪";
                            if(StoParams.Instance.register_site.Contains("太和"))
                            {
                                resMsg = "暂无发出物流，揽收后我司登记拦截 ";
                            }
                            if (StoParams.Instance.register_site.Contains("无锡锡山区东亭网点")|| StoParams.Instance.register_site.Contains("无锡锡山区查桥网点"))
                            {
                                resMsg = "未发出，可以退款";
                            }
                            if(!parcelBean.isCancelOrder)
                            {
                                StoParams.Instance.htResWechat[strBarcode] = resMsg;
                            }

                            if (StoParams.Instance.register_site.Contains("曹三") || StoParams.Instance.register_site.Contains("菊城"))
                            {
                                StoParams.Instance.htResWechat[strBarcode] = "包裹未发出无法拦截，请后台自行回收单号哦，我司后台登记包裹揽收后拦截";
                            }

                            parcelBean.replyType = "拦截无物流";
                            if(!htInterNoRoadMap.ContainsKey(strBarcode))
                            {
                                htInterNoRoadMap[strBarcode] = DateTime.Now.ToString("yyyyMMdd");
                            }
                            else
                            {
                                string oristr = htInterNoRoadMap[strBarcode] as string;
                                if(!oristr.Contains(DateTime.Now.ToString("yyyyMMdd")))
                                {
                                    oristr = oristr + "," + DateTime.Now.ToString("yyyyMMdd");
                                }
                                htInterNoRoadMap[strBarcode] = oristr;
                                string[] arr = oristr.Split(',');
                                if(arr.Length>=3)
                                {
                                    StoParams.Instance.htResWechat[strBarcode] = "快件未发出无法拦截，后续跟踪,已查询"+ arr.Length.ToString()+"天";
                                    parcelBean.replyType = "拦截无物流超3天";
                                }
                                if(htInterNoRoadMap.Count>5000)
                                {
                                    htInterNoRoadMap.Clear();
                                }
                            }
                        }
                        else
                        {
                            StoParams.Instance.htResWechat[strBarcode] = httpRes;
                        }
                        
                        continue;
                    }


                    string overTimeMention = UtilityHelp.Instance.getOverTimeParcel(arListRoadMap);
                    if(htInterNoRoadMap.ContainsKey(strBarcode))
                    {
                        htInterNoRoadMap.Remove(strBarcode);
                    }

                    FrameDecoderManager.Instance.lastSendRes = System.DateTime.Now;
                    if(DoneHttpResponse!=null)
                    {
                        DoneHttpResponse();
                    }
                    
                    string problemType = "";
                    outMsg = "";
                    string commentType = "";
                    string strInterCeptSiteCode = "";
                    /*if(JTDelayHelper.Instance.isInterceptDelay(arListRoadMap))
                    {
                        StoParams.Instance.interBarcode = strBarcode;
                        GotInterceptBarcode();

                        bool resAddCommnetIntercept = addComment(m_strCurBarcode, commentType);
                        //bool resAddCommnetIntercept = UtilityHelp.Instance.addCommentNew(m_strCurBarcode, commentType,true);
                        if (resAddCommnetIntercept)
                        {                           
                            StoParams.Instance.interBarcode = m_strCurBarcode;
                            //StoParams.Instance.interResMsg = "留言成功";
                        }
                        else
                        {
                            if (StoParams.Instance.interResMsg == "")
                            {
                                StoParams.Instance.interResMsg = "留言失败";
                            }

                        }
                        StoParams.Instance.interResMsg = m_strCurBarcode + "\r\n" +"超时未退回"+ "\r\n" + StoParams.Instance.interResMsg;
                        DoneHttpResponse();
                        Thread.Sleep(300);
                        continue;
                    }*/


                    string phoneNumber = "";
                    if (parcelBean.phoneNumList.Count > 0)
                    {
                        phoneNumber = parcelBean.phoneNumList[parcelBean.phoneNumList.Count-1];
                    }

                    string siteName = "";
                    //JTDelayHelper.Instance.parseInterceptBarcode(arListRoadMap, out commentType, out strInterCeptSiteCode,out siteName);
                    string tmpLv = "";
                    JTDelayHelper.Instance.parseManualBarcode(arListRoadMap, out commentType, out strInterCeptSiteCode, out siteName, out tmpLv);
                    string fullLeaveMsg = "";
                    if (parcelBean.ori_addr.Length > 1 && (parcelBean.ori_addr.Replace(" ", "").Contains("短少")
                            || parcelBean.ori_addr.Replace(" ", "").Contains("破损")
                             || parcelBean.ori_addr.Replace(" ", "").Contains("少件")
                             || parcelBean.ori_addr.Replace(" ", "").Contains("空包")
                            || parcelBean.ori_addr.Replace(" ", "").Contains("污染")))
                    {
                        commentType = "破损";                    
                        //res = "此件破损麻烦提供外包装破损照片内物破损照片，\r\n我司联系派件网点核实情况";
                    }
                    if (commentType.Contains("签收"))
                    {
                        if (!StoParams.Instance.register_site.Contains("廉江"))
                        {
                            parcelBean.isYishi = true;
                        }
                    }

                    if (!parcelBean.isYishi)
                    {
                        UtilityHelp.Instance.parseIsYishi(parcelBean, arListRoadMap);
                    }
                    if(UtilityHelp.Instance.parseInterceptIsOutWarehouse(parcelBean, arListRoadMap))
                    {
                        parcelBean.isOutWareHouse = true;
                    }

                    if (commentType.Contains("签收"))
                    {                       

                        ArrayList arListTmp = new ArrayList();
                        arListTmp.Add(parcelBean);
                        string errorMsg = "";
                        if(htAutoTaskAssigned.ContainsKey(parcelBean.wayBill)&& parcelBean.taskType.Contains("自动"))
                        {
                            continue;
                        }
                        addComment(phoneNumber,parcelBean.wayBill, commentType, parcelBean.ori_addr, JTDelayHelper.Instance.getInterMsg(commentType, parcelBean.ori_addr), parcelBean.wechat,out errorMsg,out fullLeaveMsg, arListRoadMap,parcelBean.isYishi);
                        if (!htAutoTaskAssigned.ContainsKey(parcelBean.wayBill) && parcelBean.taskType.Contains("自动"))
                        {
                            htAutoTaskAssigned[parcelBean.wayBill] = parcelBean.wayBill;
                        }
                        //LeaveMessageHelperGen.Instance.parseLeaveMsgBoard(arListTmp);
                        StoParams.Instance.interResMsg = " 以上订单物流已显示签收，请注意提醒客户不要取件，我司通知换单退回,如果收货了自行退回";
                        StoParams.Instance.htResWechat[parcelBean.wayBill] = " 以上订单物流已显示签收\r\n请注意提醒客户不要取件 \r\n我司通知换单退回,如果收货了自行退回,先不要退款，否则损失无法追回。";

                        if (StoParams.Instance.register_site.Contains("曹三") || StoParams.Instance.register_site.Contains("菊城"))
                        {
                            StoParams.Instance.htResWechat[parcelBean.wayBill] = " 以上单号已签收无法拦截，我司通知派件网点核实，如客户已收到，需客户自行退回哦";
                        }
                        if (overTimeMention!="")
                        {
                            StoParams.Instance.htResWechat[parcelBean.wayBill] = overTimeMention;
                        }
                        dtLastInter = System.DateTime.Now;
                        continue;
                    }

                  
                    StoParams.Instance.interResMsg = "";
                    //bool resAddCommnet = addComment(m_strCurBarcode, commentType);
                    bool resAddCommnet = false;
                    string leaveMsg = JTDelayHelper.Instance.getInterMsg(commentType, parcelBean.ori_addr);
                    
                    bool signFlag = false;
                    if(commentType!="中转")
                    {
                        /*signFlag=signProblemParcel(m_strCurBarcode, out outMsg, strInterCeptSiteCode, siteName);
                        StoParams.Instance.interResMsg = outMsg;
                        DoneHttpResponse();
                        Thread.Sleep(300);
                        StoParams.Instance.interResMsg = "刷新登记信息，等待五秒钟自动拦截";
                        DoneHttpResponse();
                        if(signFlag)
                        {
                            Thread.Sleep(1000);
                        }*/
                        
                    }
                    string interceptMsg = "";
                    bool resInter = interceptProblemParcel(arListRoadMap, m_strCurBarcode, out outMsg);

                    if(outMsg.Contains("已签收"))
                    {
                        ArrayList arListTmp = new ArrayList();
                        arListTmp.Add(parcelBean);
                        string errorMsg = "";
                        if (htAutoTaskAssigned.ContainsKey(parcelBean.wayBill) && parcelBean.taskType.Contains("自动"))
                        {
                            continue;
                        }
                        addComment(phoneNumber, parcelBean.wayBill, commentType, parcelBean.ori_addr, JTDelayHelper.Instance.getInterMsg(commentType, parcelBean.ori_addr), parcelBean.wechat, out errorMsg, out fullLeaveMsg, arListRoadMap, parcelBean.isYishi);
                        if (!htAutoTaskAssigned.ContainsKey(parcelBean.wayBill) && parcelBean.taskType.Contains("自动"))
                        {
                            htAutoTaskAssigned[parcelBean.wayBill] = parcelBean.wayBill;
                        }
                        //LeaveMessageHelperGen.Instance.parseLeaveMsgBoard(arListTmp);
                        StoParams.Instance.interResMsg = " 以上订单物流已显示签收，请注意提醒客户不要取件，我司通知换单退回,如果收货了自行退回";
                        StoParams.Instance.htResWechat[parcelBean.wayBill] = " 以上订单物流已显示签收\r\n请注意提醒客户不要取件 \r\n我司通知换单退回,如果收货了自行退回,先不要退款，否则损失无法追回。";
                        if (overTimeMention != "")
                        {
                            StoParams.Instance.htResWechat[parcelBean.wayBill] = overTimeMention;
                        }
                        dtLastInter = System.DateTime.Now;
                        continue;
                    }

                    if (!resInter && parcelBean.taskType.Contains("自动"))
                    {
                        bool interceptFinally = false;
                        if (parcelBean.taskType.Contains("自动"))
                        {
                            LogHelper.Instance.writeLog(parcelBean.taskType + " " + strBarcode + " 失败：" + outMsg);
                        }

                        if (outMsg.Contains("寄件人地址信息缺失"))
                        {
                            bool resCur = interceptProblemParcel_Single(arListRoadMap, m_strCurBarcode, out outMsg);
                            if (resCur)
                            {
                                interceptFinally = true;
                                StoParams.Instance.interResMsg = outTransferMsg + " 以上订单已联系网点拦截退回，麻烦通知收件人拒收此件，若已退款成功 请务必告知我们 谢谢";
                                StoParams.Instance.htResWechat[m_strCurBarcode] = outTransferMsg + " 以上订单已联系网点拦截退回，\r\n麻烦通知收件人拒收此件 \r\n若已退款成功请务必告知我们,谢谢";

                                if (StoParams.Instance.register_site.Contains("无锡锡山区东亭网点") || StoParams.Instance.register_site.Contains("无锡锡山区查桥网点"))
                                {
                                    StoParams.Instance.interResMsg = outTransferMsg + " 已拦截可以退款";
                                    StoParams.Instance.htResWechat[m_strCurBarcode] = outTransferMsg + " 已拦截可以退款";
                                }

                                if (StoParams.Instance.register_site.Contains("蓬江") || StoParams.Instance.register_site.Contains("邓岗") || StoParams.Instance.register_site.Contains("水洲"))
                                {
                                    string resMsg = "已登记拦截";
                                    if(parcelBean.ori_addr.Length<10)
                                    {
                                        resMsg = resMsg + " ,麻烦下次携带收件人信息电话等联系方式信息，以便后续跟踪。";
                                    }
                                    StoParams.Instance.htResWechat[m_strCurBarcode] = resMsg;
                                }
                                if (StoParams.Instance.register_site.Contains("佛山") || StoParams.Instance.register_site.Contains("东升") || StoParams.Instance.register_site.Contains("百安"))
                                {
                                    StoParams.Instance.htResWechat[m_strCurBarcode] = "拦截成功";
                                }

                                if (StoParams.Instance.register_site.Contains("曹三") || StoParams.Instance.register_site.Contains("菊城"))
                                {
                                    StoParams.Instance.htResWechat[m_strCurBarcode] = "以上单号已登记拦截";
                                }

                                if (parcelBean.isOutWareHouse)
                                {
                                    StoParams.Instance.htResWechat[m_strCurBarcode] = outTransferMsg + " 拦截处理，派件及驿站入库拦截有风险，请联系客户拒收勿取件，勿提前退款，如客户已签收，请联系客户自行退回处理";

                                    if (StoParams.Instance.register_site.Contains("永平") || (StoParams.Instance.register_site.Contains("均禾")))
                                    {
                                        string lastStauts = UtilityHelp.Instance.getLastValidStatus(arListRoadMap);
                                        if (lastStauts.Contains("派件"))
                                        {
                                            StoParams.Instance.htResWechat[m_strCurBarcode] = "已派件麻烦通知客户拒收，以免取走造成损失";
                                        }
                                        else if (lastStauts.Contains("第三方"))
                                        {
                                            StoParams.Instance.htResWechat[m_strCurBarcode] = "亲亲 已入库请务必留言客户不要取件，客户取件会造成贵司损失，我司尝试通知哦";
                                        }
                                    }
                                    if (StoParams.Instance.register_site.Contains("曹三") || StoParams.Instance.register_site.Contains("菊城"))
                                    {
                                        StoParams.Instance.htResWechat[m_strCurBarcode] = "已通知退回，派送中或存放驿站的件有拦截失败的风险，期间请勿给客户退款，麻烦次日有退回物流更新再给客户退款，否则我司无法追责遗失哦";
                                    }
                                }
                                LogHelper.Instance.writeLog(m_strCurBarcode + " 寄件人地址信息缺失 最终拦截成功");
                            }

                            if (overTimeMention != "")
                            {
                                StoParams.Instance.htResWechat[parcelBean.wayBill] = overTimeMention;
                            }
                        }
                        if (!interceptFinally)
                        {
                            if (!htInterCeptFaile.ContainsKey(m_strCurBarcode))
                            {
                                InterCeptFail interCeptFail = new InterCeptFail();
                                interCeptFail.failCount = 1;
                                interCeptFail.parcelBean = parcelBean;
                                htInterCeptFaile[m_strCurBarcode] = interCeptFail;
                            }
                            else
                            {
                                InterCeptFail interCeptFail = htInterCeptFaile[m_strCurBarcode] as InterCeptFail;
                                interCeptFail.failCount = interCeptFail.failCount + 1;
                                htInterCeptFaile[m_strCurBarcode] = interCeptFail;
                            }
                            continue;
                        }
                        else
                        {
                            resInter = true;
                        }

                    }
                    interceptMsg = outMsg;
                    dtLastInter = System.DateTime.Now;

                    if (outMsg.Contains("寄件人地址信息缺失")&& !parcelBean.taskType.Contains("自动"))
                    {
                        resInter=interceptProblemParcel_Single(arListRoadMap, m_strCurBarcode, out outMsg);
                    }

                    if (resInter)
                    {
                        if(outTransferMsg.Length>5)
                        {
                            outTransferMsg = "此件存在改地址审核\r\n" + outTransferMsg;
                        }
                        StoParams.Instance.interResMsg = outTransferMsg+ " 以上订单已联系网点拦截退回，麻烦通知收件人拒收此件，若已退款成功 请务必告知我们 谢谢";
                        StoParams.Instance.htResWechat[m_strCurBarcode] = outTransferMsg + " 以上订单已联系网点拦截退回，\r\n麻烦通知收件人拒收此件 \r\n若已退款成功请务必告知我们,谢谢";
                        if (StoParams.Instance.register_site.Contains("佛山")|| StoParams.Instance.register_site.Contains("东升") || StoParams.Instance.register_site.Contains("百安"))
                        {
                            StoParams.Instance.htResWechat[m_strCurBarcode] = "拦截成功";
                        }
                        if (StoParams.Instance.register_site.Contains("无锡锡山区东亭网点") || StoParams.Instance.register_site.Contains("无锡锡山区查桥网点"))
                        {
                            StoParams.Instance.htResWechat[m_strCurBarcode] = "已拦截可以退款";
                        }

                        if (StoParams.Instance.register_site.Contains("蓬江") || StoParams.Instance.register_site.Contains("邓岗") || StoParams.Instance.register_site.Contains("水洲"))
                        {
                            string resMsg = "已登记拦截";
                            if (parcelBean.ori_addr.Length < 10)
                            {
                                resMsg = resMsg + " ,麻烦下次携带收件人信息电话等联系方式信息，以便后续跟踪。";
                            }
                            StoParams.Instance.htResWechat[m_strCurBarcode] = resMsg;
                        }

                        if (StoParams.Instance.register_site.Contains("曹三") || StoParams.Instance.register_site.Contains("菊城"))
                        {
                            StoParams.Instance.htResWechat[m_strCurBarcode] = "以上单号已登记拦截";
                        }


                        SiteBean siteN = new SiteBean();
                        string msg = "已登记拦截";
                        if(UtilityHelp.Instance.isLastRoadMapIsProblem(arListRoadMap, siteN,out msg))
                        {
                            StringBuilder sbTmp = new StringBuilder();
                            sbTmp.AppendLine(StoParams.Instance.htResWechat[m_strCurBarcode].ToString());
                            sbTmp.AppendLine(msg);
                            StoParams.Instance.htResWechat[m_strCurBarcode] = sbTmp.ToString();
                        }

                        if (parcelBean.isOutWareHouse)
                        {
                            parcelBean.replyType = "出仓件拦截";
                            StoParams.Instance.htResWechat[m_strCurBarcode] = outTransferMsg + " 拦截处理，派件及驿站入库拦截有风险，请联系客户拒收勿取件，勿提前退款，次日确认退回成功再给客户退款哦。如客户已签收，请联系客户自行退回处理";

                            if (StoParams.Instance.register_site.Contains("永平") || (StoParams.Instance.register_site.Contains("均禾")))
                            {
                                string lastStauts = UtilityHelp.Instance.getLastValidStatus(arListRoadMap);
                                if (lastStauts.Contains("派件"))
                                {
                                    StoParams.Instance.htResWechat[m_strCurBarcode] = "已派件麻烦通知客户拒收，以免取走造成损失";
                                }
                                else if (lastStauts.Contains("第三方"))
                                {
                                    StoParams.Instance.htResWechat[m_strCurBarcode] = "亲亲 已入库请务必留言客户不要取件，客户取件会造成贵司损失，我司尝试通知哦";
                                }
                            }

                            if (parcelBean.ori_addr.Length < 10)
                            {
                                StoParams.Instance.htResWechat[m_strCurBarcode] = StoParams.Instance.htResWechat[m_strCurBarcode].ToString() + " ,麻烦下次携带收件人信息电话等联系方式信息，以便后续跟踪。";
                            }
                            if (StoParams.Instance.register_site.Contains("无锡锡山区东亭网点") || StoParams.Instance.register_site.Contains("无锡锡山区查桥网点"))
                            {
                                StoParams.Instance.htResWechat[m_strCurBarcode] = "留言退回，不可以退款";
                            }

                            if (StoParams.Instance.register_site.Contains("曹三") || StoParams.Instance.register_site.Contains("菊城"))
                            {
                                StoParams.Instance.htResWechat[m_strCurBarcode] = "已通知退回，派送中或存放驿站的件有拦截失败的风险，期间请勿给客户退款，麻烦次日有退回物流更新再给客户退款，否则我司无法追责遗失哦";
                            }

                        }
                        StoParams.Instance.curInterCeptSuccess = m_strCurBarcode;
                        if(this.GotInterceptBarcode!=null)
                        {
                            this.GotInterceptBarcode.Invoke();
                        }

                        if (overTimeMention != "")
                        {
                            StoParams.Instance.htResWechat[parcelBean.wayBill] = overTimeMention;
                        }
                    }
                    
                    string errMsg = "";
                    bool canLeanveMsg = true;
                    if(JTDelayHelper.Instance.isNoSiteToLeaveMsg(arListRoadMap, pickName))
                    {
                        canLeanveMsg = false;
                    }

                    

                    if (!resInter&&parcelBean.taskType.Contains("自动"))
                    {
                        canLeanveMsg = false;
                    }
           
                    if(canLeanveMsg)
                    {
                       
                        resAddCommnet = addComment(phoneNumber,m_strCurBarcode, commentType, parcelBean.ori_addr, leaveMsg, parcelBean.wechat, out errMsg,out fullLeaveMsg, arListRoadMap,parcelBean.isYishi);
                        if(resAddCommnet)
                        {
                            StoParams.Instance.curInterCeptSuccess = m_strCurBarcode;
                        }
                        
                    }
                    else
                    {
                        resAddCommnet = true;
                    }
                    bool isAddSignProblem = false;
                    if(fullLeaveMsg.Length<10)
                    {
                        fullLeaveMsg = leaveMsg;
                    }
                    bool isLeaveFirstCenter = true;
                    if (!JTDelayHelper.Instance.isParcelLeaveFirstCenter(arListRoadMap, pickName))
                    {
                        isLeaveFirstCenter = false;
                    }

                    if(siteName.Contains("网点") && siteName != StoParams.Instance.register_site)
                    {
                        
                        string signMsg = "";

                        if(!resInter&& parcelBean.taskType.Contains("自动"))
                        {

                        }
                        else
                        {
                            if(!StoParams.Instance.register_site.Contains("禅"))
                            {
                                signFlag = signProblemParcel(m_strCurBarcode, out signMsg, strInterCeptSiteCode, siteName, fullLeaveMsg, commentType);
                                if (signFlag)
                                {
                                    isAddSignProblem = true;
                                }
                            }
                            
                        }
                        
                    }
                    else
                    {
                        //判断转运是否超过72小时
                        if(JTDelayHelper.Instance.isInCenterMoreThan73Hours(arListRoadMap, siteName, pickName))
                        {
                            
                            string signMsg = "";
                            if (!resInter && parcelBean.taskType.Contains("自动"))
                            {

                            }
                            else
                            {
                                if (!StoParams.Instance.register_site.Contains("禅"))
                                {
                                    signFlag = signProblemParcel(m_strCurBarcode, out signMsg, strInterCeptSiteCode, siteName, fullLeaveMsg, commentType);
                                    if (signFlag)
                                    {
                                        isAddSignProblem = true;
                                    }
                                }
                                    
                            }
                            
                        }
                        //此逻辑为江门要添加问题件登记
                        else
                        {
                            if (canLeanveMsg)
                            {
                                string signMsg = "";
                                if (!StoParams.Instance.register_site.Contains("禅"))
                                {
                                    signFlag = signProblemParcel(m_strCurBarcode, out signMsg, strInterCeptSiteCode, siteName, fullLeaveMsg, commentType);
                                    if (signFlag)
                                    {
                                        isAddSignProblem = true;
                                    }
                                }
                                    
                            }
                        }

                    }
                    /*if (siteName.Contains("网点")&& siteName!=StoParams.Instance.register_site)
                    {
                        isAddSignProblem = true;
                        string signMsg = "";
                        signFlag = signProblemParcel(m_strCurBarcode, out signMsg, strInterCeptSiteCode, siteName, fullLeaveMsg, commentType);
                    }*/

                    if (resAddCommnet)
                    {
                        if(!resInter)
                        {
                            StoParams.Instance.interBarcode = m_strCurBarcode;
                            if(canLeanveMsg)
                            {
                                StoParams.Instance.interResMsg = "已留言退回";
                            }
                            
                            if(outMsg.Contains("入库")|| outMsg.Contains("运单已签收"))
                            {
                                //if(StoParams.Instance.register_site.Contains("后宅")|| StoParams.Instance.register_site.Contains("阳江"))
                                if (!isAddSignProblem)
                                {
                                    if (!resInter && parcelBean.taskType.Contains("自动"))
                                    {

                                    }
                                    else
                                    {
                                        if (!StoParams.Instance.register_site.Contains("禅"))
                                        {
                                            signFlag = signProblemParcel(m_strCurBarcode, out outMsg, strInterCeptSiteCode, siteName, fullLeaveMsg, commentType);
                                        }
                                           
                                    }
                                    
                                }                                
                                StoParams.Instance.htResWechat[m_strCurBarcode] = "快件已入库，无法拦截 "  + " 已留言退回";
                                if (StoParams.Instance.register_site.Contains("佛山")|| 
                                    StoParams.Instance.register_site.Contains("东升")||
                                    StoParams.Instance.register_site.Contains("百安"))
                                {
                                    StoParams.Instance.htResWechat[m_strCurBarcode] = "派件中通知退回。请先不要退款，派件中的件有拦截失败的风险，需要客户配合拒收，请等系统更新退回物流确定拦截了再退款哦。";
                                }
                                if (outMsg.Contains("运单已签收"))
                                {
                                    StoParams.Instance.htResWechat[m_strCurBarcode] = "运单已签收，无法申请，无法拦截\r\n " + " 已留言退回";
                                }
                                parcelBean.replyType = "拦截件已入库";
                            }
                            else if(outMsg.Contains("审核"))
                            {
                                StoParams.Instance.htResWechat[m_strCurBarcode] = "系统中存在待审核 " + " 已留言退回";

                                if (StoParams.Instance.register_site.Contains("无锡锡山区东亭网点") || StoParams.Instance.register_site.Contains("无锡锡山区查桥网点"))
                                {
                                    StoParams.Instance.htResWechat[m_strCurBarcode] = "已拦截可以退款";
                                }

                                if (StoParams.Instance.register_site.Contains("曹三") || StoParams.Instance.register_site.Contains("菊城"))
                                {
                                    StoParams.Instance.htResWechat[m_strCurBarcode] = "系统中存在退回记录，已催促尽快退回哦";
                                }
                            }
                            else if (outMsg.Contains("请求失败，运单不存在"))
                            {
                                StoParams.Instance.htResWechat[m_strCurBarcode] = "请求失败，运单不存在";
                            }
                            else if (outMsg.Contains("无法重复登记")||outMsg.Contains("重复申请"))
                            {
                                //StoParams.Instance.htResWechat[m_strCurBarcode] = "系统中存在申请记录，无法重复登记！ " + " 已留言退回";
                                StoParams.Instance.htResWechat[m_strCurBarcode] = "系统中存在退回记录，已催促尽快退回哦";
                                string outCpMsg = "";
                                if(UtilityHelp.Instance.isOnWayBack(arListRoadMap,StoParams.Instance.register_site,out outCpMsg))
                                {
                                    if(outCpMsg.Length>3)
                                    {
                                        StoParams.Instance.htResWechat[m_strCurBarcode] = outCpMsg;
                                    }
                                   
                                }
                                else
                                {
                                    if (outCpMsg.Length > 3)
                                    {
                                        StoParams.Instance.htResWechat[m_strCurBarcode] = outCpMsg;
                                    }
                                    if (StoParams.Instance.register_site.Contains("永平") || (StoParams.Instance.register_site.Contains("均禾")))
                                    {
                                        string lastStauts = UtilityHelp.Instance.getLastValidStatus(arListRoadMap);
                                        if (lastStauts.Contains("派件"))
                                        {
                                            StoParams.Instance.htResWechat[m_strCurBarcode] = "已派件麻烦通知客户拒收，以免取走造成损失";
                                        }
                                        else if (lastStauts.Contains("第三方"))
                                        {
                                            StoParams.Instance.htResWechat[m_strCurBarcode] = "亲亲 已入库请务必留言客户不要取件，客户取件会造成贵司损失，我司尝试通知哦";
                                        }
                                    }
                                }

                                if (StoParams.Instance.register_site.Contains("无锡锡山区东亭网点") || StoParams.Instance.register_site.Contains("无锡锡山区查桥网点"))
                                {
                                    if(!parcelBean.isOutWareHouse)
                                    {
                                        StoParams.Instance.htResWechat[m_strCurBarcode] = "已拦截可以退款";
                                    }
                                    else
                                    {
                                        StoParams.Instance.htResWechat[m_strCurBarcode] = "留言退回，不可以退款";
                                    }
                                   
                                }
                            }
                            else if (outMsg.Contains("特殊件不允许登记退转"))
                            {
                                StoParams.Instance.htResWechat[m_strCurBarcode] = orderSource+ "特殊件不允许登记退转\r\n " + " 已留言退回";
                            }
                            else
                            {
                                StoParams.Instance.htResWechat[m_strCurBarcode] = "拦截失败 " + " 已留言退回";
                            }

                            if (overTimeMention != "")
                            {
                                StoParams.Instance.htResWechat[parcelBean.wayBill] = overTimeMention;
                            }

                        }
                        
                    }
                    else
                    {
                        if (StoParams.Instance.interResMsg == "")
                        {
                            //StoParams.Instance.interResMsg = "留言失败";
                            string returnMySite = "";
                            if (JTDelayHelper.Instance.isLastSiteIsMyself(arListRoadMap, out returnMySite))
                            {
                                StoParams.Instance.htResWechat[m_strCurBarcode] = returnMySite;
                                continue;
                            }
                            else
                            {
                                if(outMsg.Contains("请勿重复申请"))
                                {
                                    StoParams.Instance.interResMsg = "以上单号已拦截过了哦，请不要重复发起拦截";
                                    StoParams.Instance.htResWechat[m_strCurBarcode] = "系统中存在退回记录，已催促尽快退回哦";
                                }
                                else
                                {
                                    StoParams.Instance.interResMsg = "拦截失败:" + StoParams.Instance.resMsg + " " + errMsg;
                                    StoParams.Instance.htResWechat[m_strCurBarcode] = outTransferMsg + " 拦截失败" + " " + errMsg;
                                }
                                
                            }
                            
                        }

                        if (overTimeMention != "")
                        {
                            StoParams.Instance.htResWechat[parcelBean.wayBill] = overTimeMention;
                        }

                    }
                    StoParams.Instance.interResMsg = m_strCurBarcode + "\r\n" + StoParams.Instance.interResMsg;
                    if(DoneHttpResponse!=null)
                    {
                        DoneHttpResponse();
                    }
                    

                    if(StoParams.Instance.htResWechat.ContainsKey(parcelBean.wayBill))
                    {
                        if(StoParams.Instance.htResWechat[parcelBean.wayBill].ToString().Contains("待审核"))
                        {
                            StoParams.Instance.htResWechat[parcelBean.wayBill] = "以上单号已拦截过了哦，请不要重复发起拦截";
                        }
                    }
                    Thread.Sleep(200);

                    StoParams.Instance.interResMsg = outMsg;




          
                }
                if(arListNoRoadMap.Count>0)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach(ParcelBean par in arListNoRoadMap)
                    {
                        sb.AppendLine(par.wayBill);
                    }
                    /*if(StoParams.Instance.register_site.Contains("邓岗"))
                    {
                        LogHelper.Instance.writeLog("拦截无物流，自动取消的单号"+ sb.ToString());
                        CancelOrderHelperGen.Instance.parseCancels(arListNoRoadMap);
                    }*/
                    if (StoParams.Instance.register_site.Contains("曹三") || StoParams.Instance.register_site.Contains("菊城") || StoParams.Instance.register_site.Contains("小榄"))
                    {
                        LogHelper.Instance.writeLog("拦截无物流，自动取消的单号" + sb.ToString());
                        CancelOrderHelperGen.Instance.parseCancels(arListNoRoadMap);
                    }




                }
                

            }
            catch(Exception ex)
            {
                isInProcess = false;
                StoParams.Instance.resMsg = "请求失败，请重新登录";
                if(DoneHttpResponse!=null)
                {
                    DoneHttpResponse();
                }
                
            }
            isInProcess = false;
        }

        private bool interceptProblemParcel(ArrayList arListRoadMap, string strCurBarcode, out string msg)
        {
            msg = "";
            bool res = false;
            try
            {
                string strUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/interceptTurnBack/batchQueryRegister";

                if (StoParams.Instance.isRabbitWin)
                {
                    //strUrl = "https://wdgw.jtexpress.com.cn/operatingplatform/interceptTurnBack/batchQueryRegister";

                    strUrl = "https://wdgw.jtexpress.com.cn/ops/wdbutler/rebackTransferExpress/findByWaybillNo?waybillNo=" + strCurBarcode.Trim() + "&applyTypeCode=3";
                }
                JObject jObj = new JObject();

                JArray jarry = new JArray();
                jObj["countryId"] = "1";
                jObj["applyTypeCode"] = 3;
                jarry.Add(strCurBarcode);
                jObj["waybillNos"] = jarry;
                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string resMsg = "";
                if(!StoParams.Instance.isRabbitWin)
                {
                    resMsg = HttpClient.HttpUtil.Instance.PostCommon(strUrl, postData, "interceptQueryBackNew");
                }
                else
                {
                    resMsg = HttpClient.HttpUtil.Instance.QueryCommon(strUrl, postData, "GET", "returnAndForwardMaintainAddSite");

                }
                 
                if(resMsg.Contains("运单不存在"))
                {
                    //msg = "请求失败，运单不存在";
                    //return false;
                }
                if (!resMsg.Contains("请求成功"))
                {
                    msg = "请求失败";
                }
                JObject jsonObjRes = new JObject();

                jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
                JToken senderMobilePhone = null;
                if (!StoParams.Instance.isRabbitWin)
                {
                    JArray records = (JArray)jsonObjRes["data"];
                    JObject firstObj = (JObject)records[0];
                    JToken remark = firstObj["remark"];

                    JToken enteringFlag = firstObj["enteringFlag"];

                    senderMobilePhone = firstObj["senderMobilePhone"];
                    if (enteringFlag.ToString() != "1")
                    {
                        if (remark != null && remark.ToString().Length > 2)
                        {
                            msg = "拦截失败:" + remark.ToString();
                            return false;
                        }
                        else
                        {
                            msg = "拦截失败";
                            return false;
                        }
                    }
                }
                else
                {
                    JObject records = (JObject)jsonObjRes["data"];
                    senderMobilePhone = records["senderMobilePhone"];
                }



                jObj = new JObject();
                strUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/interceptTurnBack/addRegister";
                if (StoParams.Instance.isRabbitWin)
                {
                    strUrl = "https://wdgw.jtexpress.com.cn/ops/wdbutler/rebackTransferExpress/add";

                    jObj["waybillNos"] = jarry;
                }

               
                jObj["countryId"] = "1";
                jObj["applyTypeCode"] = 3;
                jObj["waybillNo"] = strCurBarcode;
                jObj["newReceiverMobilePhone"] = senderMobilePhone.ToString();
                
                postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                

              
                resMsg = HttpClient.HttpUtil.Instance.PostCommon(strUrl, postData, "interceptQueryBackNew");
                if (!resMsg.Contains("请求成功"))
                {
                    logHelp.LogHelper.Instance.writeLog("拦截失败，返回信息：" + resMsg + " token=" + MemberInfo.Instance.token);
                    jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
                    JToken msgToke = jsonObjRes["msg"];
                    msg = "拦截失败:" + msgToke.ToString();
                    return false;
                }
                else
                {
                    msg = "拦截成功";
                    res = true;
                    return true;
                }
                //jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
            }
            catch (Exception ex)
            {

            }


            return res;
        }



        private bool interceptProblemParcel_Single(ArrayList arListRoadMap, string strCurBarcode, out string msg)
        {
            msg = "";
            bool res = false;
            try
            {
                string strUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/rebackTransferExpress/findByWaybillNo?waybillNo="+ strCurBarcode + "&applyTypeCode=3";

                if (StoParams.Instance.isRabbitWin)
                {
                    strUrl = "https://wdgw.jtexpress.com.cn/ops/wdbutler/rebackTransferExpress/findByWaybillNo?waybillNo="+ strCurBarcode+"&applyTypeCode=3";
                }

                JObject jObj = new JObject();
                JArray jarry = new JArray();
                jObj["current"] = 1;
                jObj["size"] = 20;
                jObj["countryId"] = "1";
                jObj["applyTypeCode"] = 3;
                jarry.Add(strCurBarcode);
                jObj["waybillIds"] = jarry;
                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);

                string resMsg = HttpClient.HttpUtil.Instance.QueryCommon(strUrl, postData, "GET", "returnAndForwardMaintainAddSite");
                JObject jsonObj = (JObject)JsonConvert.DeserializeObject(resMsg);
                JToken status = (JToken)jsonObj["code"];

                if (!resMsg.Contains("请求成功"))
                {
                    msg = "请求失败";
                    //return false;
                }
                JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
                JObject records = (JObject)jsonObjRes["data"];
                JToken receiverProvinceId = records["receiverProvinceId"];
                JToken receiverProvinceName = records["receiverProvinceName"];

                JToken receiverCityId = records["receiverCityId"];
                JToken receiverCityName = records["receiverCityName"];

                JToken receiverAreaId = records["receiverAreaId"];
                JToken receiverAreaName = records["receiverAreaName"];
                

                JObject newSenderProvince = JTDelayHelperNew.Instance.packageArea(receiverProvinceId, receiverProvinceName);
                JObject newSenderCity = JTDelayHelperNew.Instance.packageArea(receiverCityId, receiverCityName);
                JObject newSenderArea = JTDelayHelperNew.Instance.packageArea(receiverAreaId, receiverAreaName);


                JObject newRecProvince = JTDelayHelperNew.Instance.packageArea(records["senderProvinceId"], records["senderProvinceName"]);
                JObject newRecCity = JTDelayHelperNew.Instance.packageArea(records["senderCityId"], records["senderCityName"]);
                JObject newRecArea = JTDelayHelperNew.Instance.packageArea(records["senderAreaId"], records["senderAreaName"]);

                records["newReceiverArea"] = newRecArea;
                records["newReceiverAreaId"] = newRecArea["id"];
                records["newReceiverAreaName"] = newRecArea["cnName"];

                records["newReceiverCity"] = newRecCity;
                records["newReceiverCityId"] = records["senderCityId"];
                records["newReceiverCityName"] = records["senderCityName"];
                records["newReceiverDetailedAddress"] = records["senderDetailedAddress"];
                records["newReceiverMobilePhone"] = records["senderMobilePhone"];


                records["newSenderProvince"] = newSenderProvince;
                records["newSenderProvinceId"] = records["receiverProvinceId"];
                records["newSenderProvinceName"] = records["receiverProvinceName"];

                records["newSenderCityId"] = records["receiverCityId"];
                records["newSenderCityName"] = records["receiverCityName"];


                records["newSenderAreaId"] = newSenderArea["id"];
                records["newSenderAreaName"] = newSenderArea["cnName"];

                records["newSenderCity"] = newSenderCity;
                records["newSenderArea"] = newSenderArea;


                records["countryId"] = "1";

                records["newSenderName"] = records["receiverName"];
                records["newSenderMobilePhone"] = records["receiverMobilePhone"];
                records["newSenderTelphone"] = records["receiverTelphone"];

                records["newSenderTownship"] = records["receiverTownship"];
                records["newSenderStreet"] = records["receiverStreet"];
                records["newSenderDetailedAddress"] = records["receiverDetailedAddress"];


                records["newReceiverProvince"] = newRecProvince;
                records["newReceiverCity"] = newRecCity;
                records["newReceiverArea"] = newRecArea;

                records["newReceiverProvinceId"] = records["senderProvinceId"];
                records["newReceiverProvinceName"] = records["senderProvinceName"];


                records["newPackageChargeWeight"] = records["packageChargeWeight"];

                records["applyTypeCode"] =3;



                strUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/rebackTransferExpress/add";
                if (StoParams.Instance.isRabbitWin)
                {
                    strUrl = "https://wdgw.jtexpress.com.cn/ops/wdbutler/rebackTransferExpress/add";
                }

                postData = Newtonsoft.Json.JsonConvert.SerializeObject(records);
                resMsg = HttpClient.HttpUtil.Instance.PostCommon(strUrl, postData, "returnAndForwardMaintainAddSite");
                if (!resMsg.Contains("请求成功"))
                {
                    logHelp.LogHelper.Instance.writeLog("拦截失败，返回信息：" + resMsg + " token=" + MemberInfo.Instance.token);
                    jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
                    JToken msgToke = jsonObjRes["msg"];
                    msg = "拦截失败:" + msgToke.ToString();
                    return false;
                }
                else
                {
                    msg = "拦截成功";
                    res = true;
                    return true;
                }
                //jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
            }
            catch (Exception ex)
            {

            }


            return res;
        }

        private bool interceptProblemParcel_old(ArrayList arListRoadMap, string strCurBarcode,out string msg)
        {
            msg = "";
            bool res = false;
            try
            {
                string strUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/rebackTransferExpress/getBatchRebackWaybill";
                JObject jObj = new JObject();

                JArray jarry = new JArray();
                jObj["current"] = 1;
                jObj["size"] = 20;
                jObj["countryId"] = "1";
                jObj["applyTypeCode"] = 3;
                jarry.Add(strCurBarcode);
                jObj["waybillIds"] = jarry;
                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string resMsg = HttpClient.HttpUtil.Instance.PostCommon(strUrl, postData, "returnAndForwardMaintain");
                if (!resMsg.Contains("请求成功"))
                {
                    msg = "请求失败";
                    //return false;
                }
                JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
                JArray records = (JArray)jsonObjRes["data"];
                if (records.Count == 0)
                {
                    //msg = strCurBarcode + " 查询失败,跳过拦截环节";
                    //return false;
                }
                strUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/rebackTransferExpress/addRebackExpress";
                jObj = new JObject();
                jObj["countryId"] = "1";
                jObj["applyTypeCode"] = 3;
                jObj["waybillNo"] = strCurBarcode;
                postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                resMsg = HttpClient.HttpUtil.Instance.PostCommon(strUrl, postData, "returnAndForwardMaintain");
                if (!resMsg.Contains("请求成功"))
                {
                    logHelp.LogHelper.Instance.writeLog("拦截失败，返回信息："+ resMsg+" token="+ MemberInfo.Instance.token);
                    jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
                    JToken msgToke = jsonObjRes["msg"];
                    msg = "拦截失败:"+ msgToke.ToString();
                    return false;
                }
                else
                {
                    msg = "拦截成功";
                    res = true;
                    return true;
                }
                //jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
            }
            catch (Exception ex)
            {

            }


            return res;
        }

        public bool signProblemParcel(string strCurBarcode,out string msg,string strInterCeptSiteCode,string siteName,string fullLeaveMsg,string commentType)
        {                     
            if(fullLeaveMsg.Length>100)
            {
                fullLeaveMsg = fullLeaveMsg.Substring(0, 100);
            }

            //if (StoParams.Instance.register_site.Contains("茂名"))
            {
                fullLeaveMsg = fullLeaveMsg.Replace("，", ",");
                fullLeaveMsg = fullLeaveMsg.Replace("延误仲裁查件", "");
                fullLeaveMsg = fullLeaveMsg.Replace("遗失仲裁查件", "");
                fullLeaveMsg = fullLeaveMsg.Replace("破损仲裁查件", "");
                fullLeaveMsg = fullLeaveMsg.Trim().TrimStart(',');
            }
            msg = "";
            bool res = false;
            try
            {
                /*string strQueryUrl = "https://jmsgw.jtexpress.com.cn/servicequality/problemPiece/queryOperationType?waybillNo=" + strCurBarcode;
                if (StoParams.Instance.isRabbitWin)
                {
                    strQueryUrl = "https://wdgw.jtexpress.com.cn/servicequality/problemPiece/queryOperationType?waybillNo=" + strCurBarcode;
                }
                JObject jObj = new JObject();
                JArray jarry = new JArray();

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string resMsg = HttpClient.HttpUtil.Instance.QueryCommon(strQueryUrl, postData, "GET", "batchProblem");
                if (!resMsg.Contains("请求成功"))
                {
                    msg = "登记失败";
                    return false;
                }

                JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);   
                JArray records = (JArray)jsonObjRes["data"];
                if (records.Count == 0)
                {
                    msg = "登记失败";
                    return false;
                }
                string codeStr = "";
                for (int i=0;i< records.Count;i++)
                {
                    JObject jsonObjFirst = (JObject)records[0];
                    JToken codeToken = jsonObjFirst["code"];
                    codeStr = codeToken.ToString();
                    if(codeStr=="4")
                    {
                        break;
                    }
                }
                codeStr = "1";

                strQueryUrl = "https://jmsgw.jtexpress.com.cn/basicdata/sysAbnormalPiece/select?size=999999&levelType=1&operatorType=" + codeStr;

                if (StoParams.Instance.isRabbitWin)
                {
                    strQueryUrl = "https://wdgw.jtexpress.com.cn/basicdata/sysAbnormalPiece/select?size=999999&levelType=1&operatorType=" + codeStr;
                }
                jObj = new JObject();
                jarry = new JArray();

                postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                resMsg = HttpClient.HttpUtil.Instance.QueryCommon(strQueryUrl, postData, "GET", "batchProblem");
                if (!resMsg.Contains("请求成功"))
                {
                    msg = "登记失败";
                    return false;
                }

                jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
                JObject dataObj = (JObject)jsonObjRes["data"];
                records = (JArray)dataObj["records"];
                if (records.Count == 0)
                {
                    msg = "登记失败";
                    return false;
                }
                string assingType = "退回件";
                if(resMsg.Contains("退回件")&&resMsg.Contains("109,"))
                {
                    assingType = "退回件";
                    StoParams.Instance.probleTypeSubject = "return";
                }
                else if (resMsg.Contains("客户拒收") && resMsg.Contains("108,"))
                {
                    assingType = "客户拒收";
                    StoParams.Instance.probleTypeSubject = "customer";
                }*/
                


                //string strUrl = "https://jmsgw.jtexpress.com.cn/basicdata/network/select/all?current=1&size=100&name=" + strInterCeptSiteCode + "&typeIds%5B0%5D=336&queryLevel=3";
                string strUrl = "https://jmsgw.jtexpress.com.cn/servicequality/problemPiece/getPageByName?current=1&size=10&queryLevel=3&name="  + siteName;

                if (StoParams.Instance.isRabbitWin)
                {
                    strUrl = "https://wdgw.jtexpress.com.cn/servicequality/problemPiece/getPageByName?current=1&size=10&queryLevel=3&name=" + siteName;
                }

                JObject jObj = new JObject();
                JArray jarry = new JArray();

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string resMsg = HttpClient.HttpUtil.Instance.QueryCommon(strUrl, postData, "GET", "batchProblem");
                if(!resMsg.Contains("请求成功"))
                {
                    msg = "登记失败";
                    return false;
                }
                JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
                JObject jsonObjData = (JObject)jsonObjRes["data"];
                JArray records = (JArray)jsonObjData["records"];
                if(records.Count==0)
                {
                    msg = "网点编码："+ strInterCeptSiteCode+" 不存在,跳过登记环节";
                    return false;
                }
                string signStieCode = "";
                int receiveNetworkId = 0;
                for (int i=0;i< records.Count;i++)
                {
                    JObject json = (JObject)records[i];
                    JToken code = json["code"];
                    JToken id = json["id"];
                    if (code!=null)
                    {
                        if(code.ToString()== strInterCeptSiteCode|| id.ToString()== strInterCeptSiteCode)
                        {
                            signStieCode = code.ToString();
                            if(id!=null)
                            {
                                receiveNetworkId = Convert.ToInt32(id);
                            }
                            break;
                        }
                    }
                }
                if(signStieCode==""|| receiveNetworkId==0)
                {
                    msg = "网点编码：" + strInterCeptSiteCode + " 不存在,跳过登记环节";
                    return false;
                }


                string firstLevelTypeName = "退回件";
                int probleTypeSubjectId = 109;
                int probleTypeSubjectId2 = 100032;
                string problemTypeSubjectCode = "17";
                string secondLevelTypeCode = "17a";
                int secondLevelTypeId = 100032;
                string secondLevelTypeName = "退回件a";

                if(commentType.Contains("派件")&& StoParams.Instance.isCuiTypeWhenAssign)
                {
                    firstLevelTypeName = "催件";
                    probleTypeSubjectId = 100123;
                    probleTypeSubjectId2 = 100124;
                    problemTypeSubjectCode = "50";
                    secondLevelTypeCode = "50a";
                    secondLevelTypeId = 100124;
                    secondLevelTypeName = "催件a";
                }
                bool resSign = signType(out msg, secondLevelTypeName, probleTypeSubjectId, probleTypeSubjectId2,
                                        problemTypeSubjectCode, secondLevelTypeCode, secondLevelTypeId, receiveNetworkId, strCurBarcode, fullLeaveMsg);
                if(resSign)
                {
                    return true;
                }

                return resSign;



            }
            catch(Exception ex)
            {

            }

            
         
            return res;
        }

        private bool signType(out string msg,string secondLevelTypeName, int probleTypeSubjectId, int probleTypeSubjectId2,
                                        string problemTypeSubjectCode,string secondLevelTypeCode, int secondLevelTypeId,int receiveNetworkId,string strCurBarcode
            ,string fullLeaveMsg)
        {
            if(fullLeaveMsg.Length>100)
            {
                fullLeaveMsg = "此件麻烦尽快退回，客户已拒收，商家急催，避免客户投诉，如已遗失，麻烦联系我司处理理赔";
            }
            msg = "";
            bool res = false;
            try
            {
                string strUrl = "https://jmsgw.jtexpress.com.cn/servicequality/problemPiece/registration";
                if (StoParams.Instance.isRabbitWin)
                {
                    strUrl = "https://wdgw.jtexpress.com.cn/servicequality/problemPiece/registration";
                }

                string routerName = "batchProblem";
                JObject jObj = new JObject();
                jObj["countryId"] = "1";
                jObj["defaultKnow"] = null;
                jObj["firstLevelTypeName"] = secondLevelTypeName;
                jObj["knowNetwork"] = "";
                jObj["paths"] = "";
                jObj["probleTypeId"] = 1;
                jObj["probleTypeSubjectId"] = probleTypeSubjectId;
                jObj["probleTypeSubjectId2"] = probleTypeSubjectId2;
                jObj["problemPieceId"] = "";
                jObj["problemTypeSubjectCode"] = problemTypeSubjectCode;
                jObj["receiveNetworkId"] = receiveNetworkId;
                jObj["replyContent"] = "";
                //jObj["probleDescription"] = "此件麻烦尽快退回，客户已拒收，商家急催，避免客户投诉，如已遗失，麻烦联系我司处理理赔 ";
                jObj["probleDescription"] = fullLeaveMsg;
                jObj["replyContentImg"] = new JArray();
                jObj["replyStatus"] = 0;
                jObj["secondLevelTypeCode"] = secondLevelTypeCode;
                jObj["secondLevelTypeId"] = probleTypeSubjectId2;
                jObj["secondLevelTypeName"] = secondLevelTypeName;
                jObj["uploadDataProp"] = "";
                jObj["waybillNo"] = strCurBarcode;
                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);

                string resMsg = HttpClient.HttpUtil.Instance.PostCommon(strUrl, postData, routerName);
                if (!resMsg.Contains("请求成功"))
                {
                    JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
                    JToken msgToke = jsonObjRes["msg"];

                    msg = "登记失败:" + msgToke.ToString();
                    return false;
                }
                else
                {
                    res = true;
                    msg = "登记成功";
                    return true;
                }
            }
            catch(Exception ex)
            {

            }
            return res;
        }

        private bool addComment(string recvPhone, string strBarCode,string commentType,
            string addr,string leavemsg,string wechat,out string  errorMsg,out string outLeaveMsg, ArrayList arListRoadMap, bool isYishi =false)
        {

            outLeaveMsg = leavemsg;
            bool ret = false;
            errorMsg = "";
            try
            {
                string strUrl = "";
                JObject jObj = new JObject();
                JArray jarry = new JArray();
                jarry.Add(strBarCode);

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string res = "";

                string msg = "";
                //ArrayList arListRoadMap = new ArrayList();
                ArrayList arListRoadGX = new ArrayList();
                //此处无需重复请求
                //arListRoadMap = JTDelayHelperNew.Instance.getRoadMap(strBarCode.Trim(), out msg, arListRoadGX);

                SiteBean siteBean = UtilityHelp.Instance.getFirstSite(res, arListRoadMap);
                if (siteBean.siteCode == "")
                {
                    siteBean = UtilityHelp.Instance.getBeanSite(arListRoadMap);
                    if(siteBean.siteName == StoParams.Instance.register_site)
                    {
                        errorMsg = "留言忽略自身网点";
                    }
                }
                //SiteBean siteBean = UtilityHelp.Instance.getLastSite(res);

                if (siteBean.siteCode == ""&& siteBean.siteId=="")
                {
                    return ret;
                }
                string origPhone = recvPhone;
                string partNumber = "";
                if (recvPhone!="")
                {
                    string phone = recvPhone;
                    if (phone.Contains("-"))
                    {
                        partNumber = phone.Substring(phone.IndexOf('-') + 1);
                        phone = phone.Substring(0, phone.IndexOf('-'));

                    }
                    recvPhone = phone;


                }

                if (siteBean.siteCode == "" && siteBean.siteId != "")
                {
                    try
                    {
                        strUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/networkInfo/getNetworkDetailInfoById?networkId=" + siteBean.siteId.Trim();

                        if (StoParams.Instance.isRabbitWin)
                        {
                            strUrl = "https://wdgw.jtexpress.com.cn/ops/wdbutler/networkInfo/getNetworkDetailInfoById?networkId=" + siteBean.siteId.Trim();
                        }
                        jObj = new JObject();
                        jarry = new JArray();
                        jarry.Add(strBarCode);

                        postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                        res = HttpClient.HttpUtil.Instance.QueryCommon(strUrl, postData, "GET", "trackingExpress");
                        if (res.Contains("请求成功"))
                        {
                            if (res.Contains("data"))
                            {
                                JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(res);

                                JObject jsonObjData = (JObject)jsonObjRes["data"]; ;
                                JToken networkCode = jsonObjData["networkCode"];
                                siteBean.siteCode = networkCode.ToString();

                            }

                        }
                    }
                    catch(Exception ex)
                    {

                    }
                    
                }
                if (StoParams.Instance.register_site.Contains(siteBean.siteName.Trim())
                    || siteBean.siteName.Trim().Contains(StoParams.Instance.register_site))
                {
                    errorMsg = "已退回揽收网点";
                    return ret;
                }
                jObj["waybillNo"] = strBarCode.Trim();
                jObj["receiveNetworkId"] = siteBean.siteId.Trim();
                jObj["fileUrl"] = "";
                jObj["receiveNetworkName"] = siteBean.siteName.Trim();
                jObj["receiveNetworkCode"] = siteBean.siteCode.Trim();
                jObj["countryId"] = "1";
                //jObj["leaveMessageType"] = 5;

                jObj["receiverPhone"] = recvPhone;
                jObj["leaveMessageType"] = 5;
                leavemsg = leavemsg.Replace("延误仲裁", "遗失仲裁");

                if (StoParams.Instance.register_site.Contains("阳江") 
                    || StoParams.Instance.register_site.Contains("太和")
                     || StoParams.Instance.register_site.Contains("吴中区城南")
                    || StoParams.Instance.register_site.Contains("邓岗")
                     || StoParams.Instance.register_site.Contains("水洲")
                    || StoParams.Instance.register_site.Contains("江门")
                    || StoParams.Instance.register_site.Contains("东亭")
                    || StoParams.Instance.register_site.Contains("查桥")
                    || StoParams.Instance.register_site.Contains("沙岗")
                    || StoParams.Instance.register_site.Contains("禅城城南")
                    || StoParams.Instance.register_site.Contains("花都新清塘")
                      || StoParams.Instance.register_site.Contains("永平")
                      || StoParams.Instance.register_site.Contains("凤岗")

                    )
                {
                    leavemsg = leavemsg.Replace("延误", "遗失");

                    if (recvPhone != "" || (StoParams.Instance.register_site.Contains("邓岗") 
                        || StoParams.Instance.register_site.Contains("太和")
                         || StoParams.Instance.register_site.Contains("水洲")
                          || StoParams.Instance.register_site.Contains("吴中区城南")
                        || StoParams.Instance.register_site.Contains("江门")
                         || StoParams.Instance.register_site.Contains("东亭")
                          || StoParams.Instance.register_site.Contains("查桥")
                          || StoParams.Instance.register_site.Contains("沙岗")
                          || StoParams.Instance.register_site.Contains("禅城城南")
                         || StoParams.Instance.register_site.Contains("花都新清塘")
                          || StoParams.Instance.register_site.Contains("永平")
                           || StoParams.Instance.register_site.Contains("凤岗")

                        ))
                    {
                        SecondTypeBean secondTypeBean = new SecondTypeBean();
                        UtilityHelp.Instance.parseSecondTypeYishiAndDelay(arListRoadMap, "遗失仲裁", secondTypeBean, StoParams.Instance.register_site);
                        if (secondTypeBean.code != "")
                        {
                            jObj["leaveMessageType"] = 3;
                            jObj["secondTypeName"] = secondTypeBean.name;
                            jObj["secondTypeCode"] = secondTypeBean.code;
                            
                        }
                    }
                }

                if(isYishi)
                {
                    leavemsg = leavemsg.Replace("延误", "遗失");

                    if (recvPhone != "")
                    {
                        SecondTypeBean secondTypeBean = new SecondTypeBean();
                        UtilityHelp.Instance.parseSecondTypeYishiAndDelay(arListRoadMap, "遗失仲裁", secondTypeBean, StoParams.Instance.register_site);
                        if (secondTypeBean.code != "")
                        {
                            jObj["leaveMessageType"] = 3;
                            jObj["secondTypeName"] = secondTypeBean.name;
                            jObj["secondTypeCode"] = secondTypeBean.code;

                        }
                    }
                }

                if(commentType.Contains("破损"))
                {
                    jObj["leaveMessageType"] = 1;
                    DestroyTypeBean desBean = new DestroyTypeBean();
                    utility.Utility.getDestoryType(addr, desBean, commentType);
                    jObj["secondTypeName"] = desBean.name;
                    jObj["secondTypeCode"] = desBean.code;

                    /*tmplete = " 破损仲裁查件, 此件贵司到件破损，核实外包装破损" + desBean.name + " 客户信息:" + addr.Replace("客户信息", "");

                    if (wechatName != "")
                    {
                        tmplete = tmplete + " 协商加微信" + wechatName;
                    }*/
                }

            



                //string tmplete = "此件已退款，商家急催要求尽快退回";
                /*if (wechat==""|| wechat.Contains("wechat"))
                {
                    wechat = MemberInfo.Instance.templeteAssign;
                }*/
                string tmplete = leavemsg+" "+addr;

                if(StoParams.Instance.register_site.Contains("曹三")|| StoParams.Instance.register_site.Contains("菊城"))
                {
                    if (tmplete.Contains(origPhone) && origPhone.Length > 7)
                    {
                        if (StoParams.Instance.register_site.Contains("曹三") || StoParams.Instance.register_site.Contains("菊城"))
                        {
                            tmplete = tmplete.Substring(0, tmplete.IndexOf(origPhone) + origPhone.Length);
                        }

                    }
                }
                if(wechat.Length>3)
                {
                    tmplete = tmplete + " 协商加微信" + wechat;
                }
                outLeaveMsg = tmplete;
               /*if(commentType=="")
               {
                   commentType = "中转";
               }
               if(commentType.Contains("中转"))
               {
                   tmplete = MemberInfo.Instance.templeteTransfer;
               }
               else if (commentType.Contains("派件"))
               {
                   tmplete = MemberInfo.Instance.templeteAssign;
               }
               else if (commentType.Contains("签收"))
               {
                   tmplete = MemberInfo.Instance.templeteQS;
               }*/
               jObj["replyContent"] = tmplete.Trim().TrimEnd(',');
                //string postUrl = "https://jmsgw.jtexpress.com.cn/servicequality/leaveMessage/add";
                string postUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/messageBoard/add";

                if (StoParams.Instance.isRabbitWin)
                {
                    postUrl = "https://wdgw.jtexpress.com.cn/ops/wdbutler/messageBoard/add";
                }
                postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);

            
                string messge = HttpClient.HttpUtil.Instance.addLeaveMessage(postUrl, postData);
                if (messge.Contains("成功"))
                {
                    ret = true;
                    StoParams.Instance.interResMsg = "留言成功-"+ siteBean.siteName;
                }
                else
                {
                    JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(messge);
                    JToken msgToken = jsonObjRes["msg"];
                    string msgStr = "";
                    if(msgToken!=null)
                    {
                        msgStr = msgToken.ToString();

                        logHelp.LogHelper.Instance.writeLog("拦截-留言-"+messge);
                        if (messge.Contains("用户请求接口次数达到限流告警"))
                        {
                            logHelp.LogHelper.Instance.writeLog("拦截-留言-用户请求接口次数达到限流告警" + messge+" token="+ MemberInfo.Instance.token);
                        }
                    }
                    StoParams.Instance.interResMsg = "留言失败-" + siteBean.siteName+" "+ msgStr;
                }
            }
            catch(Exception ex)
            {

            }
            return ret;
        }

      

        public void stopThread()
        {
            try
            {
                ArrayList arListT = new ArrayList();
                ResultBean resultBean = new ResultBean();
                if (fThreadDep != null && (fThreadDep.ThreadState == ThreadState.Running || fThreadDep.ThreadState == ThreadState.Background))
                {
                    /*if (totalQueryCount > 0)
                    {
                        resultBean.countTime = totalQueryCount;

                        updateQueryCount(resultBean);
                    }*/
                    fThreadDep.Abort();
                    if (swb != null)
                    {
                        swb.Close();
                    }

                }

    
            }
            catch (Exception ex)
            {

            }
        }


        private void initLog()
        {
            try
            {
                string dir = System.Environment.CurrentDirectory;
                bFile = new FileStream(dir + "\\error.txt", FileMode.Create);
                if (swb == null)
                {
                    swb = new StreamWriter(bFile);
                    swb.WriteLine("begin");

                }
            }
            catch (Exception ex)
            {

            }

        }


        public void logNoRoadMapBarcodes()
        {
            try
            {
                string fileName = DateTime.Now.ToString("yyyyMMdd") + "noroad.txt";
                string logFile = System.Environment.CurrentDirectory + "\\log\\" + fileName;   
                FileStream bFile = new FileStream(logFile, FileMode.Create);
                StreamWriter swb = null;
                if (swb == null)
                {
                    swb = new StreamWriter(bFile);
                }
                foreach(DictionaryEntry de in htInterNoRoadMap)
                {
                    swb.WriteLine(de.Key.ToString()+":"+ de.Value.ToString());
                }                
                swb.Close();

            }
            catch (Exception ex)
            {

            }
        }

        public void initNoRoadMap()
        {
            try
            {
                string fileName = DateTime.Now.ToString("yyyyMMdd") + "noroad.txt";
                string logFile = System.Environment.CurrentDirectory + "\\log\\" + fileName;
                foreach (string line in File.ReadLines(logFile, EncodingType.GetType(logFile)))
                {
                    if (line.Length > 2 && line.Length < 80)
                    {
                        string[] arr = line.Split(':');
                        if(arr.Length>1)
                        {
                            htInterNoRoadMap[arr[0]] = arr[1];
                        }
                        
                    }
                }
            }
            catch(Exception ex)
            {

            }
        }


    }
}
